import request from '@/utils/request';
import Axios from 'axios';
import { formatDateToString, formatDateToString2 } from '@/utils/index';

export function getCaptainQueryList({ pageNum, pageSize, queryInfo, status }) {
    return request({
        url: '/v1/head/queryList',
        method: 'post',
        data: {
            pageNum,
            pageSize
        }
    });
}

export function getCaptainAuditList({ pageNum, pageSize, condition, status }) {
    return request({
        url: '/v1/head/auditList',
        method: 'post',
        data: {
            pageNum,
            pageSize,
            condition: !!condition ? condition : undefined,
            status: !!status ? status : undefined
        }
    });
}

export function captainAdudit({ id, status }) {
    return request({
        url: '/v1/head/audit',
        method: 'patch',
        data: {
            id,
            status
        }
    });
}

export function captainStop(headId) {
    return request({
        url: `/v1/head/stop/${headId}`,
        method: 'patch'
    });
}

export function getStrategyQueryList() {
    return request({
        url: '/v1/strategy/queryList',
        method: 'get'
    });
}

export function getCaptainWithdrawList({ pageNum, pageSize, times, queryCondition, status }) {
    return request({
        url: '/v1/head/withdraw/queryList',
        method: 'post',
        data: {
            pageNum,
            pageSize,
            startTime: formatDateToString2(times[0]),
            endTime: formatDateToString2(times[1]),
            queryCondition: !!queryCondition ? queryCondition : undefined,
            status: !!status ? status : undefined
        }
    });
}

export function getWithdrawDetail(withdrawId) {
    return request({
        url: `/v1/head/withdraw/detail/${withdrawId}`,
        method: 'get'
    });
}

export function dealWithWithdraw({ withdrawId, status, comment }) {
    return request({
        url: '/v1/head/withdraw/operation',
        method: 'post',
        data: {
            withdrawId,
            status,
            comment
        }
    });
}

export function createStrategy({
    name,
    iconType,
    bonus, // 额外奖励提成比例
    minCondition, // 最低指标数
    newCustomerCount, // 下单新用户数,
    newCustomerSwitch, //  下单新用户开关,
    refundOrderCount, // 退货订单数
    refundOrderSwitch, // 退货订单数开关
    orderCountSwitch,
    orderCount,
    sellAmount, // 销售金额
    sellAmountSwitch // 销售金额开关
}) {
    return request({
        url: '/v1/strategy/create',
        method: 'post',
        data: {
            name,
            iconType,
            bonus, // 额外奖励提成比例
            minCondition, // 最低指标数
            newCustomerCount, // 下单新用户数,
            newCustomerSwitch, //  下单新用户开关,
            refundOrderCount, // 退货订单数
            refundOrderSwitch, // 退货订单数开关
            orderCountSwitch,
            orderCount,
            sellAmount, // 销售金额
            sellAmountSwitch // 销售金额开关
        }
    });
}

export function editStrategy({
    id,
    name,
    iconType,
    bonus, // 额外奖励提成比例
    minCondition, // 最低指标数
    newCustomerCount, // 下单新用户数,
    newCustomerSwitch, //  下单新用户开关,
    refundOrderCount, // 退货订单数
    refundOrderSwitch, // 退货订单数开关
    orderCountSwitch,
    orderCount,
    sellAmount, // 销售金额
    sellAmountSwitch // 销售金额开关
}) {
    return request({
        url: '/v1/strategy/edit',
        method: 'post',
        data: {
            id,
            name,
            iconType,
            bonus, // 额外奖励提成比例
            minCondition, // 最低指标数
            newCustomerCount, // 下单新用户数,
            newCustomerSwitch, //  下单新用户开关,
            refundOrderCount, // 退货订单数
            refundOrderSwitch, // 退货订单数开关
            orderCountSwitch,
            orderCount,
            sellAmount, // 销售金额
            sellAmountSwitch // 销售金额开关
        }
    });
}

export function toggleStrategy({ id, status }) {
    return request({
        url: '/v1/strategy/update/status',
        method: 'patch',
        data: {
            status,
            id
        }
    });
}

export function getCaptain(headId) {
    return request({
        url: `/v1/head/detail/${headId}`,
        method: 'get'
    });
}

export function editCaptain({
    id,
    name,
    adcode,
    address,
    city,
    community,
    communityName,
    deliveryAddress,
    district,
    latitude,
    longitude,
    memberId,
    phoneNo,
    province,
    status
}) {
    return request({
        url: '/v1/head/update',
        method: 'post',
        data: {
            id,
            adcode,
            address,
            city,
            community,
            communityName,
            deliveryAddress,
            district,
            latitude,
            longitude,
            memberId,
            name,
            phoneNo,
            province,
            status
        }
    });
}

export function getStrategyDetail(strategyId) {
    return request({
        url: `/v1/strategy/detail/${strategyId}`,
        method: 'get'
    });
}

export function getStrategyTemplate() {
    return request({
        url: `/v1/head/strategy/detail`,
        method: 'get'
    });
}

export function updateStrategyTemplate(data) {
    return request({
        url: `/v1/head/strategy/update`,
        method: 'post',
        data
    });
}

export function getAddressByl({ lng, lat }) {
    return Axios({
        url: `https://restapi.amap.com/v3/geocode/regeo?key=a1152df75c5d99de75f0afeb48339aa1&location=${lng},${lat}`,
        method: 'get'
    });
}

export function commisionQueryList(data) {
    return request({
        url: `/v1/head/commission/queryList`,
        method: 'post',
        data
    });
}

export function commisionSumary(data) {
    return request({
        url: `/v1/head/commission/summary`,
        method: 'get',
        data
    });
}

export function commisionYetSettle(data) {
    return request({
        url: `/v1/head/commission/yetSettle`,
        method: 'post',
        data
    });
}
